package com.travelsmart.client.apresentacao.widget;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DecoratedPopupPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Widget;

public class FormButton extends FormWidget<String>{

	private Button button = null;
	private String valor = "";
	public FormButton(final String label, final String infoHelp, final HandlerValidation handler){
		super(handler);
		button = new Button(new SafeHtml() {
			private static final long serialVersionUID = 6938780873202424773L;
			@Override
			public String asString() {
				return label;
			}
		}, new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				if(!validar()){
					final DecoratedPopupPanel helpPopup = new DecoratedPopupPanel(true);
				    helpPopup.ensureDebugId("cwBasicPopup-simplePopup");
				    helpPopup.setWidth("150px");
				    helpPopup.setWidget(new HTML(getValue()));
					Widget source = (Widget) event.getSource();
		            int left = source.getAbsoluteLeft() + 10;
		            int top = source.getAbsoluteTop() + 10;
		            helpPopup.setPopupPosition(left, top);
		            helpPopup.show();
				}
			}
		});
		button.setTitle(infoHelp);
		initHelp(infoHelp);
		initWidget(button);
		
	}
	
	@Override
	public String getValue() {
		// TODO Auto-generated method stub
		return valor;
	}
	public void setValue(String valor) {
		// TODO Auto-generated method stub
		this.valor = valor;
	}
	@Override
	public void setFocus(boolean focused) {
		button.setFocus(false);
		
	}

}
